
package net.atremmedia.gwt.actionjava.examples.basics.samples;

import net.atremmedia.gwt.actionjava.examples.AJExample;
import net.atremmedia.gwt.actionjava.examples.frame.AJExampleOverview;
import actionjava.display.Graphics;
import actionjava.display.Sprite;
import actionjava.events.tick.TickEvent;
import actionjava.geom.Color;

public class Wave2 extends AJExample
{
	public static final String NAME = "Wave 2";
	public static final String DESCRIPTION = "Description";
	public static final String EXAMPLE_SRC = "https://code.google.com/p/gwt-actionjava/source/browse/trunk/aj-examples/aj-examples-basics/src/main/java/net/atremmedia/gwt/actionjava/examples/basics/samples/Wave2.java";

	private Sprite waveSprite;
	private Graphics waveGraphs;

	private double angle = 0;
	private double centerY = 200;
	private double range = 50;
	private double xspeed = 1;
	private double yspeed = .05;
	private double xpos = 0;
	private double ypos = 0;

	public Wave2(AJExampleOverview base)
	{
		super(NAME, DESCRIPTION, EXAMPLE_SRC, base);
	}

	private void initialize()
	{
		angle = 0;
		centerY = 200;
		range = 50;
		xspeed = 1;
		yspeed = .05;
		xpos = 0;
		ypos = 0;
	}

	@Override
	public void run()
	{
		initialize();

		waveSprite = new Sprite();
		waveGraphs = waveSprite.getGraphics();

		waveGraphs.beginStroke(Color.BLACK.getHexValue());
		waveGraphs.setStrokeStyle(1);
		waveGraphs.moveTo(0, centerY);

		addChild(waveSprite);
	}

	@Override
	public void onRenderTick(TickEvent event)
	{
		xpos += xspeed;
		angle += yspeed;
		ypos = centerY + Math.sin(angle) * range;
		waveGraphs.lineTo(xpos, ypos);
	}
}
